﻿using Xamarin.Forms;

namespace Games.Box
{
    class GameCell : Image
    {
        public static readonly ImageSource ImgTarget = ImageSource.FromFile("box_Target.png");
        public static readonly ImageSource ImgWall = ImageSource.FromFile("box_Wall.png");
        public static readonly ImageSource ImgBox = ImageSource.FromFile("box_Box.png");
        public static readonly ImageSource ImgBoxOnPlace = ImageSource.FromFile("box_BoxOnPlace.png");
        public static readonly ImageSource ImgMan = ImageSource.FromFile("box_Man.png");
        private byte status;
        public GameCell(int id, byte status)
        {
            this.status = status;
            if(id == 0)
            {
                this.Source = ImgMan;
            }
            else if(id > 0)
            {
                if(this.status == CellStatus.Box)
                {
                    this.Source = ImgBox;
                }
                else if(this.status == CellStatus.BoxOnPlace)
                {
                    this.Source = ImgBoxOnPlace;
                }
            }
            else
            {
                if(status == CellStatus.Wall)
                {
                    this.Source = ImgWall;
                }
                else if((status & CellStatus.Target) == CellStatus.Target)
                {
                    this.Source = ImgTarget;
                }
            }
        }

        public byte Status
        {
            get
            {
                return this.status;
            }
            set
            {
                if(this.status != value)
                {
                    this.status = value;
                    if(this.status == CellStatus.Box)
                    {
                        this.Source = ImgBox;
                    }
                    else if(this.status == CellStatus.BoxOnPlace)
                    {
                        this.Source = ImgBoxOnPlace;
                    }
                }
            }
        }
    }
}
